package com.sanjiayi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sanjiayi.pojo.ChatMessage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
    
    @Select("SELECT * FROM chat_message WHERE " +
            "sender_id = #{userId} OR receiver_id = #{userId} " +
            "GROUP BY LEAST(sender_id, receiver_id), GREATEST(sender_id, receiver_id) " +
            "ORDER BY create_time DESC")
    List<ChatMessage> selectRecentChats(Integer userId);
} 